<?php
class DelAttach extends Action {
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$aids = safe_ids ( rqst ( 'aid' ), ',', true );
		if (! empty ( $aids )) {
			$atM = new WebAttachmentModel ();
			foreach ( $aids as $aid ) {
				$att = $atM->read ( $aid );
				$rst = false;
				if ($att) {
					$file = WWW_ROOT . $att ['url'];
					$rst = $atM->delete ( $aid );
				}
				if ($rst !== false && file_exists ( $file )) {
					if (@unlink ( $file )) {
						ImageUtil::deleteThumbnail ( $file );
					}				
				}
			}
		}
		Response::redirect ( './' );
	}

}